package com.mmd.parkingspringboot.config;

import com.mmd.parkingspringboot.mapper.ManageMapper;
import com.mmd.parkingspringboot.mapper.UserMapper;
import com.mmd.parkingspringboot.model.LoginUser;
import com.mmd.parkingspringboot.model.Manage;
import com.mmd.parkingspringboot.model.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;


@Service
public class LoginImpl implements UserDetailsService {
    @Autowired
    private ManageMapper mapper;
    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {

        Manage user = mapper.manageLogin(username);
        if (user != null){

            UserDetails loginUser = new LoginUser(user);
            return loginUser;
        }else {
            throw  new RuntimeException("用户名或者密码错误！！！！");
        }
    }
}
